var configs = {
    s_url:$.trim($(".shop_site_path").val()),
    api_key:$.trim($(".shop_api_key").val()),
    api_sgin:$.trim($(".shop_api_sgin").val()),
    user_id:$.trim($(".shop_user_id").val())
}
var registerHttpHelper = {
    s_url:configs.s_url,
    params:'json={"api_key":"'+configs.api_key+'","api_sgin":"'+configs.api_sgin+'","client_type":2,"ver":13,',
    data:{
        si:"",  //倒计时
        isSendVercode:false
    },
    countTime:function(){ //倒计时开始
        var timer =60;
        $("#J-timer").text(timer);
        clearInterval(registerHttpHelper.data.si);
        registerHttpHelper.data.si = setInterval(function() {
            timer--;
            $("#J-timer").text(timer);
            if (timer == 0) {
                clearInterval(registerHttpHelper.data.si);
                $(".J-getVerCode").removeClass("am-hide");
                $("#J-countTime").addClass("am-hide");
            }
        }, 1000);
    },
    getVerifyCode:function(mobile,currentObj){
        var params ='json={"api_key":"'+configs.api_key+'","service":"Grain.getVerifyCode","client_type":3,"task_id":"verCode","type":1,"mobile":"'+mobile+'"}';
        this.doPost(params,currentObj);
    },
    getShopType:function(currentObj){
        var params = registerHttpHelper.params+'"m":"t_26_tongyongpeizhibiao","map":[["id","eq","57"]],"service":"Grain.select","p":0,"page_size":20,"task_id":"peizhi"}';
        this.doPost(params,currentObj);
    },
    getArea:function(pid,ptype,currentObj){
        if(ptype==1){
            var params = registerHttpHelper.params+'"m":"t_26_chinaarea","map":[["pid","eq","0"]],"service":"Grain.select","p":0,"page_size":30,"task_id":"chinaarea"}';
        }else{
            var params = registerHttpHelper.params+'"m":"t_26_chinaarea","map":[["pid","eq","'+pid+'"]],"service":"Grain.select","p":0,"page_size":30,"task_id":"chinaarea"}';
        }
        this.doPost(params,currentObj,ptype);
    },

    doPost:function(params,currentObj,ptype){
        var result = {};
        $.ajax({
            type:"post",
            url:this.s_url,
            dataType:'json',
            data:params,
            beforeSend:function(){
                Loading =layer.msg('努力加载中...', {icon: 16,shade: [0.5, '#f5f5f5'],scrollbar: false,offset: '40%', time:100000}) ;

            },
            success:function Response(data){
                layer.close(Loading);
                registerHttpHelper.callback(data,currentObj,ptype);
            }
        });
        return result;
    },
    callback:function(obj,currentObj,ptype){
        switch (obj.task_id){
            case 'peizhi':
                if(obj.code==200) {
                    if(obj.list.length>0){
                        if(obj.list[0].config_value){
                            var a=obj.list[0].config_value;
                            var	a = a.substring(1,a.length - 1).replace(/\"/g, "");
                            var b=a.split(",");
                            var html='';	html+='	<option value="">请选择店铺类型</option>';
                            for(var i=0;i< b.length;i++){
                                html+='	<option value="'+b[i]+'">'+b[i]+'</option>'
                            }
                        }
                        currentObj.append(html);
                    }
                }else{
                    alert('error');
                }
                break;
            case 'verCode':
                if(obj.code==200) {
                    $(".J-getVerCode").addClass("am-hide");
                    $("#J-countTime").removeClass("am-hide");
                    registerHttpHelper.countTime();
                }else{
                    alert('error');
                }
                break;
            case 'chinaarea':
                if(obj.code==200) {

                    if(obj.list.length>0) {
                        currentObj.html("");
                        var html = '';
                        if(ptype==1){
                            html += '	<option value="">请选择省</option>';
                        }else if(ptype==2){
                            html += '	<option value="">请选择市</option>';
                        }else{
                            html += '	<option value="">请选择区</option>';
                        }

                        for (var i = 0; i < obj.list.length; i++) {
                            html += '	<option value="' + obj.list[i].id + '">' + obj.list[i].name + '</option>'
                        }

                        currentObj.append(html);
                    }
                }else{
                    alert('error');
                }
                break;

            default :
                alert('error');
                break;
        }
    }
}
